﻿using Application.CodeRuleService;
using Application.DictTypeService;
using Domain.Entity.sys;
using Domain.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WMSManage.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]//需要鉴权
    public class DictTypeController : ControllerBase
    {
        private readonly IDictTypeService dictTypeService;

        public DictTypeController(IDictTypeService dictTypeService)
        {
            this.dictTypeService = dictTypeService;
        }


      
        /// <summary>
        /// 分页查询字典类型信息
        /// </summary>
        /// <param name="name">类型名</param>
        /// <param name="status">状态</param>
        /// <param name="createname">创建人</param>
        /// <param name="starttime">开始时间</param>
        /// <param name="endtime">结束时间</param>
        /// <param name="CurrentPage">当前页</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<FenYe<DictType>> GetDictType(string? name, int? status, string? createname, string? starttime, string? endtime, int CurrentPage)
        {
            FenYe<DictType> fenYe = new FenYe<DictType>()
            {
                CurrentPage = CurrentPage,
            };
            return await dictTypeService.GetDictType(fenYe, name, status, createname, starttime, endtime);
        }


        /// <summary>
        /// 添加字典类型信息
        /// </summary>
        /// <param name="addDictTypeDto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddDictType(AddDictTypeDto addDictTypeDto)
        {
            return await dictTypeService.AddDictType(addDictTypeDto);
        }



        /// <summary>
        /// 删除字典类型信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> DeleteDictType(int id)
        {
            return await dictTypeService.DeleteDictType(id);
        }



        /// <summary>
        /// 根据id查询字典类型信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<DictType> GetDictTypeById(int id)
        {
            return await dictTypeService.GetDictTypeById(id);
        }



        /// <summary>
        /// 修改字典类型信息
        /// </summary>
        /// <param name="updateDictTypeDto"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateDictType(UpdateDictTypeDto updateDictTypeDto)
        {
            return await dictTypeService.UPdateDictType(updateDictTypeDto);
        }


        /// <summary>
        /// 查询所有字典类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<DictType>> GetType()
        {
            return await dictTypeService.GetType();
        }
    }
}
